home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / CONSTRAI / STD_EXT_.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  29.2 KB  |  833 lines

  1.  
  2. package sub_arctic.constraints;
  3.  
  4. import sub_arctic.lib.interactor_consts;
  5. import sub_arctic.lib.interactor;
  6. import sub_arctic.lib.manager;
  7. import sub_arctic.lib.sub_arctic_error;
  8.  
  9. import java.awt.Point;
  10. import java.util.Vector;
  11.  
  12. /** This class provides an external constraint that executes one of the
  13.  *  standard constraint functions based on a (partial) standard constraint
  14.  *  encoding along with an explicit set of operands (which involve explicitly
  15.  *  provided objects and standard or non-standard parts).
  16.  */
  17. public class std_ext_constraint extends external_constraint {
  18.  
  19.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  20.  
  21.   /** Partial encoding of the constraint.  This controls how the constraint
  22.    *  operates and is encoded the same way as a standard constraint encoding
  23.    *  (see std_encoding_consts) except that the encoded operands and constant
  24.    *  are ignored.
  25.    */
  26.   protected int _encoding = std_constraint_consts.NO_CONSTRAINT.encoding();  
  27.  
  28.   /** Partial encoding of the constraint.  This controls how the constraint
  29.    *  operates and is encoded the same way as a standard constraint encoding
  30.    *  (see std_encoding_consts) except that the encoded operands and constant
  31.    *  are ignored.
  32.    */
  33.   public int encoding() {return _encoding;}
  34.  
  35.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  36.  
  37.   /** Constant value passed to the constraint evaluation function.  */
  38.   protected int _const_value = 0;
  39.  
  40.   /** Constant value passed to the constraint evaluation function.  */
  41.   public int const_value() {return _const_value;}
  42.  
  43.   /** Set the constant value passed to the constraint evaluation function. */
  44.   public void set_const_value(int v) 
  45.     {
  46.       _const_value = v;
  47.  
  48.       /* mark our selves out of date */
  49.       value_ood(0, null, 0);
  50.     }
  51.  
  52.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  53.  
  54.   /** Orientation under which this constraint is evaluated.  This should match
  55.    *  the orientation of the object to which this constraint is attached and
  56.    *  only affects implicit operands (i.e., self.wh used in centered()), and
  57.    *  does not affect explicit operands which maintain their own orientation.
  58.    *  This should have one of the values HORIZONTAL, VERTICAL, or NOT_ORIENTED.
  59.    */
  60.   protected byte _orientation;
  61.  
  62.   /** Orientation under which this constraint is evaluated.  This should match
  63.    *  the orientation of the object to which this constraint is attached and
  64.    *  only affects implicit operands (i.e., self.wh used in centered()), and
  65.    *  does not affect explicit operands which maintain their own orientation.
  66.    *  This should have one of the values HORIZONTAL, VERTICAL, or NOT_ORIENTED.
  67.    */
  68.   public byte orientation() {return _orientation;}
  69.  
  70.   /** Set the orientation under which this constraint is evaluated.  This 
  71.    *  should match the orientation of the object to which this constraint is 
  72.    *  attached and only affects implicit operands (i.e., self.wh used in 
  73.    *  centered()), and does not affect explicit operands which maintain their 
  74.    *  own orientation. This should have one of the values HORIZONTAL, VERTICAL,
  75.    *  or NOT_ORIENTED.
  76.    */
  77.   public void set_orientation(int ov) {_orientation = (byte)ov;}
  78.  
  79.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  80.  
  81.   /** The object which serves as self for the constraint.  This object should
  82.    *  be the one that contains the part being constrained and controls the 
  83.    *  coordinate system in which position values are delivered.  */
  84.   protected interactor _self_obj = null;
  85.  
  86.   /** The object which serves as self for the constraint.  This object should
  87.    *  be the one that contains the part being constrained and controls the 
  88.    *  coordinate system in which position values are delivered.  */
  89.   public interactor self_obj() {return _self_obj;}
  90.  
  91.   /** Set the object which serves as self for the constraint.  This object 
  92.    *  should be the one that contains the part being constrained and controls 
  93.    *  the coordinate system in which position values are delivered.  */
  94.   public void set_self_obj(interactor slf_obj) {_self_obj = slf_obj;}
  95.  
  96.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  97.  
  98.   /** Flag value for non-standard part code.  This can be stored in 
  99.    *  op*_std_part to indicate that a non-standard part is being referred to 
  100.    *  (in which case op*_part will contain the part number being referenced).  */
  101.   public static final byte NOT_STANDARD = (byte)0xff;
  102.  
  103.   /** Bit mask for bit used to indicate a horizontally oriented standard part.
  104.    *  This bit will be set in op*_std_part if the part is to be interpreted
  105.    *  as having a horizontal orientation.
  106.    */
  107.   public static final byte IS_HORIZ = (byte)0x40;
  108.  
  109.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  110.  
  111.   /** Standard part code for operand 1.  If this has the special value 
  112.    *  NOT_STANDARD, then a non-standard part (found in _op1_part) is used
  113.    *  instead. Otherwise this will contain a standard part code (one of the
  114.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  115.    *  should be interpreted with a horizontal orientation. */
  116.   protected byte _op1_std_part = NOT_STANDARD;
  117.  
  118.   /** Standard part code for operand 1.  If this has the special value 
  119.    *  NOT_STANDARD, then a non-standard part (found in _op1_part) is used
  120.    *  instead. Otherwise this will contain a standard part code (one of the
  121.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  122.    *  should be interpreted with a horizontal orientation. */
  123.   public byte op1_std_part() {return _op1_std_part;}
  124.  
  125.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  126.  
  127.   /** Standard part code for operand 2.  If this has the special value 
  128.    *  NOT_STANDARD, then a non-standard part (found in _op2_part) is used
  129.    *  instead. Otherwise this will contain a standard part code (one of the
  130.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  131.    *  should be interpreted with a horizontal orientation. */
  132.   protected byte _op2_std_part = NOT_STANDARD;
  133.  
  134.   /** Standard part code for operand 2.  If this has the special value 
  135.    *  NOT_STANDARD, then a non-standard part (found in _op2_part) is used
  136.    *  instead. Otherwise this will contain a standard part code (one of the
  137.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  138.    *  should be interpreted with a horizontal orientation. */
  139.   public byte op2_std_part() {return _op2_std_part;}
  140.  
  141.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  142.  
  143.   /** Standard part code for operand 3.  If this has the special value 
  144.    *  NOT_STANDARD, then a non-standard part (found in _op3_part) is used
  145.    *  instead. Otherwise this will contain a standard part code (one of the
  146.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  147.    *  should be interpreted with a horizontal orientation. */
  148.   protected byte _op3_std_part = NOT_STANDARD;
  149.  
  150.   /** Standard part code for operand 3.  If this has the special value 
  151.    *  NOT_STANDARD, then a non-standard part (found in _op3_part) is used
  152.    *  instead. Otherwise this will contain a standard part code (one of the
  153.    *  PARTCODE_* values) optionally ORed with IS_HORIZ to indicate that it 
  154.    *  should be interpreted with a horizontal orientation. */
  155.   public byte op3_std_part() {return _op3_std_part;}
  156.  
  157.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  158.  
  159.   /** Non-standard part number for operand 1 of the constraint.  This is used
  160.    *  if op1_std_part == NON_STANDARD, and will contain the part number of
  161.    *  the part providing operand 1. */
  162.   protected int _op1_part;
  163.  
  164.   /** Non-standard part number for operand 1 of the constraint.  This is used
  165.    *  if op1_std_part == NON_STANDARD, and will contain the part number of
  166.    *  the part providing operand 1. */
  167.   public int op1_part() {return _op1_part;}
  168.  
  169.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  170.  
  171.   /** Object referenced by operand 1 of the constraint.  */
  172.   protected interactor _op1_obj = null;
  173.  
  174.   /** Object referenced by operand 1 of the constraint.  */
  175.   public interactor op1_obj() {return _op1_obj;}
  176.  
  177.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  178.  
  179.   /** Non-standard part number for operand 2 of the constraint.  This is used
  180.    *  if op2_std_part == NON_STANDARD, and will contain the part number of
  181.    *  the part providing operand 2. */
  182.   protected int _op2_part;
  183.  
  184.   /** Non-standard part number for operand 2 of the constraint.  This is used
  185.    *  if op2_std_part == NON_STANDARD, and will contain the part number of
  186.    *  the part providing operand 2. */
  187.   public int op2_part() {return _op2_part;}
  188.  
  189.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  190.  
  191.   /** Object referenced by operand 2 of the constraint.  */
  192.   protected interactor _op2_obj = null;
  193.  
  194.   /** Object referenced by operand 2 of the constraint.  */
  195.   public interactor op2_obj() {return _op2_obj;}
  196.  
  197.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  198.  
  199.   /** Non-standard part number for operand 3 of the constraint.  This is used
  200.    *  if op3_std_part == NON_STANDARD, and will contain the part number of
  201.    *  the part providing operand 3. */
  202.   protected int _op3_part;
  203.  
  204.   /** Non-standard part number for operand 3 of the constraint.  This is used
  205.    *  if op3_std_part == NON_STANDARD, and will contain the part number of
  206.    *  the part providing operand 3. */
  207.   public int op3_part() {return _op3_part;}
  208.  
  209.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  210.  
  211.   /** Object referenced by operand 3 of the constraint.  */
  212.   protected interactor _op3_obj = null;
  213.  
  214.   /** Object referenced by operand 3 of the constraint.  */
  215.   public interactor op3_obj() {return _op3_obj;}
  216.  
  217.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  218.  
  219.   /** Cache of number of operands for the encoded function */
  220.   protected int _num_ops = 0;
  221.  
  222.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  223.  
  224.   /** Construct a 3 operand external constraint that executes the constraint
  225.    *  function encoded in standard from, but with arbitrary operand values.<p> 
  226.    *
  227.    * @param int        enc     The (partial) standard encoding for the 
  228.    *                           constraint (the operand encoding portions are 
  229.    *                           ignored).
  230.    * @param interactor slf_obj The object which acts as self for the 
  231.    *                           constraint (this is only used for constraints 
  232.    *                           that implicitly reference self or parent).
  233.    * @param int        orient  Orientation of the part we are constraining.
  234.    * @param ext_objpart_encoding op1 An encoding of the first operand.
  235.    * @param ext_objpart_encoding op2 An encoding of the second operand.
  236.    * @param ext_objpart_encoding op3 An encoding of the third operand.
  237.    * @param int        c_val   The constant value supplied to the constraint.
  238.    */
  239.    public std_ext_constraint(
  240.     int enc, 
  241.     interactor slf_obj,
  242.     int        orient,
  243.     ext_objpart_encoding op1,
  244.     ext_objpart_encoding op2,
  245.     ext_objpart_encoding op3,
  246.     int c_val) 
  247. {
  248.       /* verify that we have a 3 operand function */
  249.       _num_ops = std_constraint_impl.the_impl().num_ops(enc);
  250.       if (_num_ops != 3)
  251.     throw new sub_arctic_error("Encoding for " + 
  252.       std_constraint_impl.the_impl().opcode_str(enc) + 
  253.       " cannot be used with 3 operands");
  254.  
  255.       /* save encoding, self and constant */
  256.       _encoding = enc;
  257.       _self_obj = slf_obj;
  258.       _orientation = (byte)orient;
  259.       _const_value = c_val;
  260.  
  261.       /* record all the operand parts */
  262.       if (op1.uses_std_part())
  263.     {
  264.       _op1_std_part = (byte)op1.ref_part();
  265.       if (op1.orientation() == std_encoding_consts.HORIZONTAL)
  266.         _op1_std_part |= IS_HORIZ;
  267.     }
  268.       else
  269.     {
  270.       _op1_std_part = NOT_STANDARD;
  271.       _op1_part = op1.ref_part();
  272.     }
  273.  
  274.       if (op2.uses_std_part())
  275.     {
  276.       _op2_std_part = (byte)op2.ref_part();
  277.       if (op2.orientation() == std_encoding_consts.HORIZONTAL)
  278.         _op2_std_part |= IS_HORIZ;
  279.     }
  280.       else
  281.     {
  282.       _op2_std_part = NOT_STANDARD;
  283.       _op2_part = op2.ref_part();
  284.     }
  285.  
  286.       if (op3.uses_std_part())
  287.     {
  288.       _op3_std_part = (byte)op3.ref_part();
  289.       if (op3.orientation() == std_encoding_consts.HORIZONTAL)
  290.         _op3_std_part |= IS_HORIZ;
  291.     }
  292.       else
  293.     {
  294.       _op3_std_part = NOT_STANDARD;
  295.       _op3_part = op3.ref_part();
  296.     }
  297.  
  298.       /* record all the operand objects */
  299.       _op1_obj = op1.ref_obj();
  300.       _op2_obj = op2.ref_obj();
  301.       _op3_obj = op3.ref_obj();
  302.  
  303.       /* establish dependency edges */ 
  304.       setup_dependencies();
  305.       
  306.     }
  307.  
  308.    //had:
  309.    //* @exception bad_value if the encoding does not represent a 3 operand 
  310.    //*                      function.
  311.    //* @exception general
  312.  
  313.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  314.  
  315.   /** Construct a 2 operand external constraint that executes the constraint
  316.    *  function encoded in standard from, but with potentially arbitrary 
  317.    *  operand values.<p> 
  318.    *
  319.    * @param int        enc     The (partial) standard encoding for the 
  320.    *                           constraint (the operand encoding portions are 
  321.    *                           ignored).
  322.    * @param interactor slf_obj The object which acts as self for the 
  323.    *                           constraint (this is only used for constraints 
  324.    *                           that implicitly reference self or parent).
  325.    * @param int        orient  Orientation of the part we are constraining.
  326.    * @param ext_objpart_encoding op1 An encoding of the first operand.
  327.    * @param ext_objpart_encoding op2 An encoding of the second operand.
  328.    * @param int        c_val   The constant value supplied to the constraint.
  329.    */
  330.    public std_ext_constraint(
  331.     int enc, 
  332.     interactor slf_obj,
  333.     int        orient,
  334.     ext_objpart_encoding op1,
  335.     ext_objpart_encoding op2,
  336.     int c_val) 
  337. {
  338.       /* verify that we have a 2 operand function */
  339.       _num_ops = std_constraint_impl.the_impl().num_ops(enc);
  340.       if (_num_ops != 2)
  341.     throw new sub_arctic_error("Encoding for " + 
  342.       std_constraint_impl.the_impl().opcode_str(enc) + 
  343.       " cannot be used with 2 operands");
  344.  
  345.       /* save encoding, self and constant */
  346.       _encoding = enc;
  347.       _self_obj = slf_obj;
  348.       _orientation = (byte)orient;
  349.       _const_value = c_val;
  350.  
  351.       /* record all the operand parts */
  352.       if (op1.uses_std_part())
  353.     {
  354.       _op1_std_part = (byte)op1.ref_part();
  355.       if (op1.orientation() == std_encoding_consts.HORIZONTAL)
  356.         _op1_std_part |= IS_HORIZ;
  357.     }
  358.       else
  359.     {
  360.       _op1_std_part = NOT_STANDARD;
  361.       _op1_part = op1.ref_part();
  362.     }
  363.  
  364.       if (op2.uses_std_part())
  365.     {
  366.       _op2_std_part = (byte)op2.ref_part();
  367.       if (op2.orientation() == std_encoding_consts.HORIZONTAL)
  368.         _op2_std_part |= IS_HORIZ;
  369.     }
  370.       else
  371.     {
  372.       _op2_std_part = NOT_STANDARD;
  373.       _op2_part = op2.ref_part();
  374.     }
  375.  
  376.       /* record all the operand objects */
  377.       _op1_obj = op1.ref_obj();
  378.       _op2_obj = op2.ref_obj();
  379.  
  380.       /* establish dependency edges */ 
  381.       setup_dependencies();
  382.       
  383.     }
  384.  
  385.    //had:
  386.    //* @exception bad_value if the encoding does not represent a 2 operand 
  387.    //*                      function.
  388.    //* @exception general
  389.  
  390.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  391.  
  392.   /** Construct a 1 operand external constraint that executes the constraint
  393.    *  function encoded in standard from, but with a potentially arbitrary 
  394.    *  operand value.<p> 
  395.    *
  396.    * @param int        enc     The (partial) standard encoding for the 
  397.    *                           constraint (the operand encoding portions are 
  398.    *                           ignored).
  399.    * @param interactor slf_obj The object which acts as self for the 
  400.    *                           constraint (this is only used for constraints 
  401.    *                           that implicitly reference self or parent).
  402.    * @param int        orient  Orientation of the part we are constraining.
  403.    * @param ext_objpart_encoding op1 An encoding of the second operand.
  404.    * @param int        c_val   The constant value supplied to the constraint.
  405.    */
  406.    public std_ext_constraint(
  407.     int enc, 
  408.     interactor slf_obj,
  409.     int        orient,
  410.     ext_objpart_encoding op1,
  411.     int c_val) 
  412. {
  413.       /* verify that we have a 1 operand function */
  414.       _num_ops = std_constraint_impl.the_impl().num_ops(enc);
  415.       if (_num_ops != 1)
  416.     throw new sub_arctic_error("Encoding for " + 
  417.       std_constraint_impl.the_impl().opcode_str(enc) + 
  418.       " cannot be used with 1 operand");
  419.  
  420.       /* save encoding, self and constant */
  421.       _encoding = enc;
  422.       _self_obj = slf_obj;
  423.       _orientation = (byte)orient;
  424.       _const_value = c_val;
  425.  
  426.       /* record operand part */
  427.       if (op1.uses_std_part())
  428.     {
  429.       _op1_std_part = (byte)op1.ref_part();
  430.       if (op1.orientation() == std_encoding_consts.HORIZONTAL)
  431.         _op1_std_part |= IS_HORIZ;
  432.     }
  433.       else
  434.     {
  435.       _op1_std_part = NOT_STANDARD;
  436.       _op1_part = op1.ref_part();
  437.     }
  438.  
  439.       /* record operand object */
  440.       _op1_obj = op1.ref_obj();
  441.  
  442.       /* establish dependency edges */ 
  443.       setup_dependencies();
  444.       
  445.     }
  446.  
  447.    //had:
  448.    //* @exception bad_value if the encoding does not represent a 1 operand 
  449.    //*                      function.
  450.    //* @exception general
  451.  
  452.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  453.  
  454.   /** Construct a 0 operand external constraint that executes the constraint
  455.    *  function encoded in standard from.<p>
  456.    *
  457.    * @param int        enc     The (partial) standard encoding for the 
  458.    *                           constraint (the operand encoding portions are 
  459.    *                           ignored).
  460.    * @param interactor slf_obj The object which acts as self for the 
  461.    *                           constraint (this is only used for constraints 
  462.    *                           that implicitly reference self or parent).
  463.    * @param int        orient  Orientation of the part we are constraining.
  464.    * @param int        c_val   The constant value supplied to the constraint.
  465.    */
  466.    public std_ext_constraint(
  467.     int enc, 
  468.     interactor slf_obj,
  469.     int        orient,
  470.     int c_val) 
  471. {
  472.       /* verify that we have a 0 operand function */
  473.       _num_ops = std_constraint_impl.the_impl().num_ops(enc);
  474.       if (_num_ops != 0)
  475.     throw new sub_arctic_error("Encoding for " + 
  476.       std_constraint_impl.the_impl().opcode_str(enc) + 
  477.       " cannot be used with 0 operands");
  478.  
  479.       /* save encoding, self and constant */
  480.       _encoding = enc;
  481.       _self_obj = slf_obj;
  482.       _orientation = (byte)orient;
  483.       _const_value = c_val;
  484.  
  485.       /* establish dependency edges */ 
  486.       setup_dependencies();
  487.       
  488.     }
  489.  
  490.    //had:
  491.    //* @exception bad_value if the encoding does not represent a 0 operand 
  492.    //*                      function.
  493.    //* @exception general
  494.  
  495.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  496.  
  497.   /** 
  498.    * Establish the external dependencies for a particular standard part 
  499.    * reference.<p>
  500.    * @param interactor for_obj   the object depended upon.
  501.    * @param byte       part_code the code of the part within that object we are
  502.    *                             dependent upon.  Note: this should include the
  503.    *                             IS_HORIZ bit as used in op*_std_part.
  504.    */
  505.   protected void setup_std_part_dependencies(interactor for_obj, byte part_code)
  506.     {
  507.       boolean horiz;
  508.       byte    code;
  509.  
  510.       horiz = (part_code & IS_HORIZ) != 0;
  511.       code  = (byte)(part_code & ~IS_HORIZ & 0xff);
  512.  
  513.       switch(code)
  514.     {
  515.     case std_encoding_consts.PARTCODE_XY:
  516.       if (horiz)
  517.         for_obj.attach_dependent(interactor_consts.X, this , 0);
  518.       else
  519.         for_obj.attach_dependent(interactor_consts.Y, this , 0);
  520.       break;
  521.   
  522.     case std_encoding_consts.PARTCODE_XY2:
  523.     case std_encoding_consts.PARTCODE_CENTER:
  524.       if (horiz)
  525.         {
  526.           for_obj.attach_dependent(interactor_consts.X, this , 0);
  527.           for_obj.attach_dependent(interactor_consts.W, this , 0);
  528.         }
  529.       else
  530.         {
  531.           for_obj.attach_dependent(interactor_consts.Y, this , 0);
  532.           for_obj.attach_dependent(interactor_consts.H, this , 0);
  533.         }
  534.       break;
  535.   
  536.     case std_encoding_consts.PARTCODE_WH:
  537.       if (horiz)
  538.         for_obj.attach_dependent(interactor_consts.W, this , 0);
  539.       else
  540.         for_obj.attach_dependent(interactor_consts.H, this , 0);
  541.       break;
  542.     case std_encoding_consts.PARTCODE_VISIBLE:
  543.       for_obj.attach_dependent(interactor_consts.VISIBLE, this , 0);
  544.       break;
  545.     case std_encoding_consts.PARTCODE_ENABLED:
  546.       for_obj.attach_dependent(interactor_consts.ENABLED, this , 0);
  547.       break;
  548.     case std_encoding_consts.PARTCODE_PART_A:
  549.       for_obj.attach_dependent(interactor_consts.PART_A, this , 0);
  550.       break;
  551.     case std_encoding_consts.PARTCODE_PART_B:
  552.       for_obj.attach_dependent(interactor_consts.PART_B, this , 0);
  553.       break;
  554.     }
  555.     }
  556.  
  557.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  558.  
  559.   /** 
  560.    * Setup dependencies for a particular operand. <p>
  561.    *
  562.    * @param byte op_std_part  the part (or NOT_STANDARD)
  563.    * @param interactor op_obj  the object referred to for a non-standard part.
  564.    * @param int        op_part the part referred to for a non-standard part.
  565.    */
  566.   protected void setup_op_dependencies(
  567.     byte op_std_part, interactor op_obj, int op_part)
  568.     {
  569.       /* do we a have a standard or non-standard part? */
  570.       if (op_std_part != NOT_STANDARD)
  571.     /* set up standard edges */
  572.     setup_std_part_dependencies(op_obj, op_std_part);
  573.       else
  574.     /* set up single dependency to explicitly given part */
  575.     op_obj.attach_dependent(op_part, this , 0);
  576.  
  577.     }
  578.  
  579.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  580.  
  581.   /** Establish the external dependencies needed for this constraint */
  582.   protected void setup_dependencies() 
  583. {
  584.       Vector intrins;
  585.  
  586.       /* get dependencies that are intrinsic to the function being evaluated */
  587.       intrins = std_constraint_impl.the_impl().implicit_depend_list(
  588.                     encoding(), self_obj(), orientation());
  589.  
  590.       /* walk down pairwise list of interactor/part and establish dependencies*/
  591.       for (int i = 0; i < intrins.size(); i += 2)
  592.     {
  593.       setup_std_part_dependencies((interactor)intrins.elementAt(i),
  594.           (byte)((Integer)intrins.elementAt(i+1)).intValue());
  595.     }
  596.  
  597.       /* do operand dependencies */
  598.       if (_num_ops > 0) 
  599.     setup_op_dependencies(op1_std_part(),op1_obj(),op1_part());
  600.       if (_num_ops > 1) 
  601.     setup_op_dependencies(op2_std_part(),op2_obj(),op2_part());
  602.       if (_num_ops > 2) 
  603.     setup_op_dependencies(op3_std_part(),op3_obj(),op3_part());
  604.     }
  605.  
  606.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  607.  
  608.   /** 
  609.    * Fetch a standard part from the given object. <p> 
  610.    *
  611.    * @param interactor the_obj the object we are getting the part from.
  612.    * @param int        the_part encoding of the part (including IS_HORIZ bit).
  613.    * @return int the value of the requested object part.
  614.    */
  615.   protected int fetch_std_part(interactor the_obj, int the_part) 
  616. {
  617.       boolean horiz;
  618.       int     code;
  619.       int     result;
  620.       Point   pt;
  621.  
  622.       horiz = (the_part & IS_HORIZ) != 0;
  623.       code  = the_part & ~IS_HORIZ;
  624.  
  625.       switch(code)
  626.     {
  627.       case std_encoding_consts.PARTCODE_XY:
  628.         if (horiz) 
  629.           {
  630.         /* get the value */
  631.             result = the_obj.get_part(interactor_consts.X);
  632.  
  633.         /* put it in the coordinates of the parent of self */
  634.         result = the_obj.x_into_local(result);
  635.         pt = self_obj().global_to_local(
  636.                   the_obj.local_to_global(result,0));
  637.         return self_obj().x_into_parent(pt.x);
  638.           }
  639.         else
  640.           {
  641.         /* get the value */
  642.             result = the_obj.get_part(interactor_consts.Y);
  643.  
  644.         /* put it in the coordinates of the parent of self */
  645.         result = the_obj.y_into_local(result);
  646.         pt = self_obj().global_to_local(
  647.                   the_obj.local_to_global(0,result));
  648.         return self_obj().y_into_parent(pt.y);
  649.           }
  650.  
  651.       case std_encoding_consts.PARTCODE_WH:
  652.         if (horiz)
  653.           return the_obj.get_part(interactor_consts.W);
  654.         else
  655.           return the_obj.get_part(interactor_consts.H);
  656.  
  657.       case std_encoding_consts.PARTCODE_VISIBLE:
  658.         return the_obj.get_part(interactor_consts.VISIBLE);
  659.  
  660.       case std_encoding_consts.PARTCODE_ENABLED:
  661.         return the_obj.get_part(interactor_consts.ENABLED);
  662.  
  663.       case std_encoding_consts.PARTCODE_PART_A:
  664.         return the_obj.get_part(interactor_consts.PART_A);
  665.  
  666.       case std_encoding_consts.PARTCODE_PART_B:
  667.         return the_obj.get_part(interactor_consts.PART_B);
  668.  
  669.       case std_encoding_consts.PARTCODE_XY2:
  670.         if (horiz) 
  671.           {
  672.         /* get the value */
  673.             result = the_obj.get_part(interactor_consts.X) + 
  674.              the_obj.get_part(interactor_consts.W);
  675.  
  676.         /* put it in the coordinates of the parent of self */
  677.         result = the_obj.x_into_local(result);
  678.         pt = self_obj().global_to_local(
  679.                   the_obj.local_to_global(result,0));
  680.         return self_obj().x_into_parent(pt.x);
  681.           }
  682.         else
  683.           {
  684.         /* get the value */
  685.             result = the_obj.get_part(interactor_consts.Y) + 
  686.              the_obj.get_part(interactor_consts.H);
  687.  
  688.         /* put it in the coordinates of the parent of self */
  689.         result = the_obj.y_into_local(result);
  690.         pt = self_obj().global_to_local(
  691.                   the_obj.local_to_global(0,result));
  692.         return self_obj().y_into_parent(pt.y);
  693.           }
  694.  
  695.       case std_encoding_consts.PARTCODE_CENTER:
  696.         if (horiz) 
  697.           {
  698.         /* get the value */
  699.             result = the_obj.get_part(interactor_consts.X) + 
  700.              the_obj.get_part(interactor_consts.W)/2;
  701.  
  702.         /* put it in the coordinates of the parent of self */
  703.         result = the_obj.x_into_local(result);
  704.         pt = self_obj().global_to_local(
  705.                   the_obj.local_to_global(result,0));
  706.         return self_obj().x_into_parent(pt.x);
  707.           }
  708.         else
  709.           {
  710.         /* get the value */
  711.             result = the_obj.get_part(interactor_consts.Y) + 
  712.              the_obj.get_part(interactor_consts.H)/2;
  713.  
  714.         /* put it in the coordinates of the parent of self */
  715.         result = the_obj.y_into_local(result);
  716.         pt = self_obj().global_to_local(
  717.                   the_obj.local_to_global(0,result));
  718.         return self_obj().y_into_parent(pt.y);
  719.           }
  720.  
  721.       default:
  722.         throw new sub_arctic_error("Unrecognized part code " + code + 
  723.                   " found in std_ext_constraint.fetch_std_part()");
  724.     }
  725.     }
  726.  
  727.    //had:
  728.    //* @exception bad_value if the_part is not a standard part code.
  729.  
  730.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  731.  
  732.   /**
  733.    * Fetch a standard or non-standard part from the given interactor object. <p>
  734.    *
  735.    * @param interactor from_obj object we are getting part value from.
  736.    * @param int        std_part  encoding for a standard part, or NOT_STANDARD.
  737.    * @param int        ext_part  number of non-standard part being referred to.
  738.    * @return int the value of the part.
  739.    */
  740.   protected int fetch_part(interactor from_obj, int std_part, int ext_part_num) 
  741. {
  742.       Object val;
  743.  
  744.       /* if we have no object use the fallback of a 0 value */
  745.       if (from_obj == null) return 0;
  746.  
  747.       if (std_part != NOT_STANDARD)
  748.         {
  749.           /* get/compute the standard part */
  750.           return fetch_std_part(from_obj, std_part);
  751.         }
  752.       else
  753.         {
  754.           /* get the non-standard part directly */
  755.           val = from_obj.get_value(ext_part_num);
  756.       
  757.           /* make sure we got an integer */
  758.           if (!(val instanceof Integer))
  759.             throw new sub_arctic_error("Non-integer operand value found in "+ 
  760.                             "standard external constraint");
  761.       
  762.           return ((Integer)val).intValue();
  763.         }
  764.     }
  765.  
  766.    //had:
  767.    //* @exception bad value if an improperly coded std_part or ext_part_num is 
  768.    //*                      found.
  769.    //* @exception general
  770.  
  771.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  772.  
  773.   /** 
  774.    * Actually evaluate the constraint.  Here the part number is ignored
  775.    * since we only have one exported value. <p>
  776.    *
  777.    * @param int ignored_part_number Ignored.
  778.    */
  779.   public Object get_value(int ignored_part_number) 
  780.     {
  781.       int result = 0;
  782.       int val1 = 0;
  783.       int val2 = 0;
  784.       int val3 = 0;
  785.  
  786.       switch (_num_ops)
  787.     {
  788.     case 0:
  789.       result = op0_impl.eval_fun(encoding(), self_obj(), const_value(), 
  790.                      orientation());
  791.       break;
  792.     case 1:
  793.       val1 = fetch_part(op1_obj(), op1_std_part(), op1_part());
  794.       result = op1_impl.eval_fun(encoding(), self_obj(), val1, 
  795.                      const_value(), orientation());
  796.       break;
  797.     case 2:
  798.       val1 = fetch_part(op1_obj(), op1_std_part(), op1_part());
  799.       val2 = fetch_part(op2_obj(), op2_std_part(), op2_part());
  800.       result = op2_impl.eval_fun(encoding(), self_obj(), val1, val2,
  801.                      const_value(), orientation());
  802.       break;
  803.     case 3:
  804.       val1 = fetch_part(op1_obj(), op1_std_part(), op1_part());
  805.       val2 = fetch_part(op2_obj(), op2_std_part(), op2_part());
  806.       val3 = fetch_part(op3_obj(), op3_std_part(), op3_part());
  807.       result = op3_impl.eval_fun(encoding(), self_obj(), val1, val2, 
  808.                      val3, const_value(), orientation());
  809.       break;
  810.     }
  811.       return new Integer(result);
  812.  
  813.     }
  814.  
  815.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  816. }
  817. /*=========================== COPYRIGHT NOTICE ===========================
  818.  
  819. This file is part of the subArctic user interface toolkit.
  820.  
  821. Copyright (c) 1996 Scott Hudson and Ian Smith
  822. All rights reserved.
  823.  
  824. The subArctic system is freely available for most uses under the terms
  825. and conditions described in 
  826.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  827. and appearing in full in the lib/interactor.java source file.
  828.  
  829. The current release and additional information about this software can be 
  830. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  831.  
  832. ========================================================================*/
  833.